﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="check_number_study.aspx.cs" Inherits="SQT.tracnghiem.Ajax.ASP.Accountant.check_number_study" %>

<%@ Import Namespace="DataAccess" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<body>
    <%
        var get_student = new TblUserController().FetchAll().Where(x => x.NumberStudy.ToUpper() == this.study).ToList();
        if (get_student.Count != 0)
        {
            var get_class = new TblClassController().FetchAll().Where(x => x.Id == get_student[0].ClassX).Single();
            if (this.type == 1)
            {
    %>
    <div id="error_bill_msg" class="w3-text-red w3-row w3-center"></div>
    <div id="student_id" class="w3-hide"><%=get_student[0].UserId%></div>
    <div class="w3-row w3-padding-bottom">
        <span class="w3-col l3">Họ tên</span><input class="w3-half w3-border w3-border-teal" id="detail_fullname" type="text" value="<%=get_student[0].FullName%>" disabled="disabled" />
    </div>
    <div class="w3-row w3-padding-bottom">
        <span class="w3-col l3">Lớp</span><input class="w3-half w3-border w3-border-teal" type="text" value="<%=get_class.ClassName%>" disabled="disabled" />
    </div>
    <div class="w3-row w3-padding-bottom">
        <span class="w3-col l3">Học phí</span><input class="w3-half w3-border w3-border-teal" id="detail_fee" type="number" min="0" step="50000" />
    </div>
    <div class="w3-row w3-padding-bottom">
        <span class="w3-col l3">Gói</span>
        <select class="w3-half w3-border w3-border-teal" id="ddl_detail_month">
            <option value="1">1 Tháng</option>
            <option value="2">2 Tháng</option>
            <option value="3">3 Tháng</option>
        </select>
    </div>
    <div class="w3-row w3-padding-bottom">
        <span class="w3-col l3">Ngày hết hạn</span><input id="detail_exp_date" class="w3-half w3-border w3-border-teal" type="date" />
    </div>
    <div class="w3-row w3-center">
        <a class="w3-btn w3-teal" id="btn_bill_accept"><i class="fa fa-check"></i>&nbsp;Xác nhận</a>&nbsp;
        <a onclick="$('#study-pay-modal').fadeOut()" class="w3-btn w3-teal"><i class="fa fa-times"></i>&nbsp;Hủy</a>
    </div>
    <%}
            else
            {
                var get_bill = new TblStudyFeeController().FetchAll().Where(x => x.UserId == get_student[0].UserId);
                var check_save_fee = new TblStudySaveFeeController().FetchAll().Where(x => x.UserId == get_student[0].UserId);
                    
    %>
    <div id="save_Fee_msg" class="w3-text-red w3-row w3-center"></div>
    <div id="sf_student_id" class="w3-hide"><%=get_student[0].UserId%></div>
    <div class="w3-row w3-padding-bottom">
        <span class="w3-col l3">Họ tên</span>
        <input class="w3-half w3-border w3-border-teal" type="text" value="<%=get_student[0].FullName%>" disabled="disabled" />
    </div>


    <%if (check_save_fee.ToList().Count != 0)
      {
          var get_cls = from p in new TblClassController().FetchAll() orderby p.Id descending where p.Active == true select p;%>
    <div class="w3-row w3-padding-bottom">
        <span class="w3-col l3">Lớp</span>
        <select id="sf_choose_class">
            <option value="-1">Chọn lớp</option>
            <%foreach (TblClass cls in get_cls)
              { %>
            <option value="<%=cls.Id%>"><%=cls.ClassName%></option>
            <%} %>
        </select>
    </div>
    <div class="w3-row w3-padding-bottom">
        <span class="w3-col l3">Trạng thái</span>
        <input class="w3-half w3-border w3-border-teal" type="text" value="Đang bảo lưu" disabled="disabled" />
    </div>
    <div class="w3-row w3-padding-bottom">
        <span class="w3-col l3">Số tiền bảo lưu</span>
        <input id="sf_save_days" disabled="disabled" class="w3-col l3 w3-border w3-border-teal" value="<%=check_save_fee.Single().DaysRemain%>" type="number" min="0" />
    </div>
    <div class="w3-row w3-padding-bottom">
        <span class="w3-col l3">Ngày hết hạn</span>
        <input id="sf_open_date" class="w3-half w3-border w3-border-teal" type="date" />
    </div>
    <div class="w3-row w3-center">
        <a onclick="btn_accept_open_save_fee(<%=get_student[0].UserId %>)" class="w3-btn w3-teal"><i class="fa fa-check"></i>&nbsp;Mở bảo lưu</a>
        <a onclick="$('#save-pay-modal').fadeOut()" class="w3-btn w3-teal"><i class="fa fa-times"></i>&nbsp;Hủy</a>
    </div>
    <%}
      else
      { %>
    <div class="w3-row w3-padding-bottom">
        <span class="w3-col l3">Lớp</span>
        <input id="sf_Study_Class" class="w3-half w3-border w3-border-teal" type="text" value="<%=get_class.ClassName%>" disabled="disabled" />
    </div>

    <%if (get_bill.ToList().Count != 0)
      {
          DateTime now = DateTime.Now;
          DateTime exp = DateTime.Parse(get_bill.Last().ExpDate.ToString());
          TimeSpan remain = exp.Subtract(now);
          int day = remain.Days;
          if (day > 0)
              day++;
          string exp_day = DateTime.Parse(get_bill.Last().ExpDate.ToString()).Day.ToString();
          string exp_month = DateTime.Parse(get_bill.Last().ExpDate.ToString()).Month.ToString();
          if (int.Parse(exp_day) < 10)
          {
              exp_day = "0" + exp_day;
          }
          if (int.Parse(exp_month) < 10)
          {
              exp_month = "0" + exp_month;
          }
    %>
    <div class="w3-row w3-padding-bottom">
        <span class="w3-col l3">Thời hạn học phí</span>
        <input id="sf_exp_date" disabled="disabled" value="<%=DateTime.Parse(get_bill.Last().ExpDate.ToString()).Year.ToString()+"-"+exp_month+"-"+exp_day %>" class="w3-half w3-border w3-border-teal" type="date" />
    </div>
    <div class="w3-row w3-padding-bottom">
        <span class="w3-col l3">Số tiền bảo lưu</span>
        <input id="sf_exp_day" class="w3-col l3 w3-border w3-border-teal" value="0" min="0" type="number" />
    </div>
    <%if (check_save_fee.ToList().Count == 0 && day > 3)
      { %>
    <div class="w3-row w3-padding-bottom">
        <span class="w3-col l3">Ngày bảo lưu</span>
        <input id="sf_date" class="w3-half w3-border w3-border-teal" type="date" />
    </div>
    <div class="w3-row w3-center">
        <a onclick="btn_accept_save_fee(<%=get_student[0].UserId%>)" class="w3-btn w3-teal"><i class="fa fa-check"></i>&nbsp;Xác nhận</a>
        <a onclick="$('#save-pay-modal').fadeOut()" class="w3-btn w3-teal"><i class="fa fa-times"></i>&nbsp;Hủy</a>
    </div>
    <%}}
      else
      { %>
    <div class="w3-row w3-padding-bottom">
        <span class="w3-col l3">Thời hạn học phí</span>
        <input disabled="disabled" value="Chưa đóng học phí" type="text" />
    </div>
    <%} %>
    <%
      }
            }
        }
        else
        { %>
    <div class="w3-row w3-center w3-text-red">Không tìm thấy học viên "<label><%=this.study%></label>"</div>
    <%} %>
</body>
</html>
